package com.wang.controller;

import com.wang.entity.Announcement;
import com.wang.service.AnnouncementService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/announcement")
public class AnnouncementController {
    @Resource
    private AnnouncementService announcementService;

    @RequestMapping("/add")
    public void addAnnouncement(@RequestBody Announcement announcement) {


        announcement.setPublishTime(new java.util.Date());
        System.out.println(announcement);
        announcementService.addAnnouncement(announcement);
    }

    @RequestMapping("/update")
    public void updateAnnouncement(Announcement announcement) {
        announcement.setPublishTime(new java.util.Date());
        announcementService.updateAnnouncement(announcement);
    }

    @RequestMapping("delete")
    public void deleteAnnouncement(Integer announcementId) {
        announcementService.deleteAnnouncement(announcementId);
    }


    @RequestMapping("/get")
    public List<Announcement> getAnnouncement(String title, LocalDateTime startDate, LocalDateTime endDate) {
        return announcementService.getAnnouncement(title,startDate,endDate);

    }


}

